package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.CarveUpPool;
import com.sc.nft.mapper.CarveUpPoolMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * 瓜分活动总奖池(sc_carve_up_pool)数据DAO
 *
 * @author Sun
 * @since 2023-09-14 11:25:32
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class CarveUpPoolDao extends ServiceImpl<CarveUpPoolMapper, CarveUpPool> {

    public CarveUpPool getResidualPrizePool() {
        LambdaQueryWrapper<CarveUpPool> wrapper = new LambdaQueryWrapper<>();
        wrapper.last("limit 1");
        return this.getOne(wrapper);
    }

    public Boolean subAmountByActivityBasicsId(BigDecimal initPoolReserve,Long id) {
        return baseMapper.subAmountByActivityBasicsId(id,initPoolReserve);
    }

    public Boolean addAmountByActivityBasicsId(BigDecimal initPoolReserve, Long id) {
        return baseMapper.addAmountByActivityBasicsId(id,initPoolReserve);
    }

    public void subFreezeAmount(BigDecimal subFreezeAmount, Long id) {
        UpdateWrapper<CarveUpPool> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.setSql("freeze_amount = freeze_amount - " + subFreezeAmount);
        update(new CarveUpPool(),wrapper);
    }
}